package com.bluefish.bltuan.module.shop;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;

import com.bluefish.bltuan.module.Category;
import com.bluefish.bltuan.module.Image;
import com.bluefish.bltuan.module.user.Manager;
import com.bluefish.bltuan.module.user.User;
import com.bluefish.bltuan.tools.DateUtils;
import com.bluefish.bltuan.tools.shop.AccordType;

@Entity
public class TuanGou implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -6689584929202378335L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;
	
	/**
	 * the name of this tuan gou
	 */
	private String name;
	
	private String seller;
	
	/**
	 * the nick name to get the tuan gou info
	 */
	private String nick;
	
	/**
	 * create time
	 */
	private Date createTime;
	
	/**
	 * publish time
	 */
	private Date publishTime;
	
	private String publishedDate;
	
	private boolean published;
	
	/**
	 * the time arrive the limit person
	 */
	private Date limitTime;
	
	/**
	 * the expire date
	 */
	private Date expireDate;
	
	/**
	 * the expire date String
	 */
	private String expireTime;
	
	/**
	 * the least limit buyes' number
	 */
	private int limitPerson;
	
	/**
	 * the head describe
	 */
	@Lob
	private String simpleDescribe;
	
	/**
	 * the current price
	 */
	private float currentPrice;

	/**
	 * the original price
	 */
	private float originalPrice;
	
	/**
	 * 折扣
	 */
	private float discount;
	
	/**
	 * 节省
	 */
	private float saved;
	
	/**
	 * 提示
	 */
	@Lob
	private String tip;
	
	/**
	 * 亮点
	 */
	@Lob
	private String light;
	
	@OneToOne(fetch = FetchType.LAZY)
	private Image headImg;
	
	/**
	 * 本单详情
	 */
	@Lob
	private String detail;
	
	/**
	 * 地址介绍
	 */
	@Lob
	private String address;
	
	/**
	 * 路线介绍
	 */
	@Lob
	private String traffic;
	
	/**
	 * 团购成功与否
	 */
	private boolean success;
	
	private boolean finished;
	
	@OneToOne(fetch = FetchType.LAZY)
	private Manager editor;
	
	@ManyToMany(cascade=CascadeType.REFRESH,mappedBy="tuangous")  
	private List<User> buyers;
	
	private int buyersNumber;
	
	@OneToOne(fetch = FetchType.LAZY)
	private Category city;
	
	/**
	 * 售出方式
	 * 短信,快递
	 */
	@Enumerated(EnumType.ORDINAL)
	private AccordType accordType ;
	
	/**
	 * 经度
	 */
	private String longitude;
	
	/**
	 * 纬度
	 */
	private String latitude;
	
	/**
	 * 显示精度
	 */
	private int mapLevel;
	
	/**
	 * 静态map图片
	 */
	private String mapPicLink;

	/**
	 * 动态map地址
	 */
	@Lob
	private String mapLink;
	
	private String website;

	public AccordType getAccordType() {
		return accordType;
	}

	public void setAccordType(AccordType accordType) {
		this.accordType = accordType;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getNick() {
		return nick;
	}

	public void setNick(String nick) {
		this.nick = nick;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getPublishTime() {
		return publishTime;
	}

	public void setPublishTime(Date publishTime) {
		this.publishTime = publishTime;
	}

	public Date getLimitTime() {
		return limitTime;
	}

	public void setLimitTime(Date limitTime) {
		this.limitTime = limitTime;
	}

	public void setExpireTime(String expireTime) {
		this.expireTime = expireTime;
	}
	
	public String getExpireTime() {
		return expireTime;
	}

	public int getLimitPerson() {
		return limitPerson;
	}

	public void setLimitPerson(int limitPerson) {
		this.limitPerson = limitPerson;
	}

	public String getSimpleDescribe() {
		return simpleDescribe;
	}
	
	public void setSimpleDescribe(String simpleDescribe) {
		this.simpleDescribe = simpleDescribe;
	}
	
	public float getCurrentPrice() {
		return currentPrice;
	}

	public void setCurrentPrice(float currentPrice) {
		this.currentPrice = currentPrice;
	}

	public float getOriginalPrice() {
		return originalPrice;
	}

	public void setOriginalPrice(float originalPrice) {
		this.originalPrice = originalPrice;
	}

	public float getDiscount() {
		return discount;
	}

	public void setDiscount(float discount) {
		this.discount = discount;
	}

	public float getSaved() {
		return saved;
	}

	public void setSaved(float saved) {
		this.saved = saved;
	}

	public String getTip() {
		return tip;
	}

	public void setTip(String tip) {
		this.tip = tip;
	}

	public String getLight() {
		return light;
	}

	public void setLight(String light) {
		this.light = light;
	}

	public Image getHeadImg() {
		return headImg;
	}

	public void setHeadImg(Image headImg) {
		this.headImg = headImg;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public Manager getEditor() {
		return editor;
	}

	public void setEditor(Manager editor) {
		this.editor = editor;
	}

	public List<User> getBuyers() {
		return buyers;
	}

	public void setBuyers(List<User> buyers) {
		this.buyers = buyers;
	}

	public int getBuyersNumber() {
		return buyersNumber;
	}

	public void setBuyersNumber(int buyersNumber) {
		this.buyersNumber = buyersNumber;
	}
	
	public void setPublished(boolean published) {
		this.published = published;
	}
	
	public boolean isPublished() {
		return published;
	}
	
	public void setFinished(boolean finished) {
		this.finished = finished;
	}
	
	public boolean isFinished() {
		return finished;
	}
	
	public String getPublishedDate() {
		return publishedDate;
	}
	
	public void setPublishedDate(String publishedDate) {
		this.publishedDate = publishedDate;
	}

	public String getTraffic() {
		return traffic;
	}

	public void setTraffic(String traffic) {
		this.traffic = traffic;
	}

	public String getSeller() {
		return seller;
	}

	public void setSeller(String seller) {
		this.seller = seller;
	}
	
	public Category getCity() {
		return city;
	}
	
	public void setCity(Category city) {
		this.city = city;
	}

	public String getLongitude() {
		return longitude;
	}

	public void setLongitude(String longitude) {
		this.longitude = longitude;
	}

	public String getLatitude() {
		return latitude;
	}

	public void setLatitude(String latitude) {
		this.latitude = latitude;
	}

	public String getMapLink() {
		return mapLink;
	}

	public void setMapLink(String mapLink) {
		this.mapLink = mapLink;
	}

	public int getMapLevel() {
		return mapLevel;
	}
	
	public void setMapLevel(int mapLevel) {
		this.mapLevel = mapLevel;
	}
	
	public void setMapPicLink(String mapPicLink) {
		this.mapPicLink = mapPicLink;
	}
	
	public String getMapPicLink() {
		return mapPicLink;
	}

	public Date getExpireDate() {
		return expireDate;
	}

	public void setExpireDate(Date expireDate) {
		this.expireDate = expireDate;
	}
	
	public boolean isRunning(){
		String today = DateUtils.getDateString(new Date());
		return published && today.compareTo(publishedDate) >= 0 &&
			today.compareTo(expireTime) < 0;
	}
	
	public boolean isPast(){
		String today = DateUtils.getDateString(new Date());
		return today.compareTo(expireTime) >= 0;
	}
	
	public boolean isFuture(){
		String today = DateUtils.getDateString(new Date());
		return today.compareTo(publishedDate) < 0;
	}
	
	public String getWebsite() {
		return website;
	}
	
	public void setWebsite(String website) {
		this.website = website;
	}
}
